package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Employee;
import com.itheima.reggie.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.Objects;

@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    //登录功能
    @PostMapping("/employee/login")
    public ResultInfo login(@RequestBody Employee employee) {
        String password = employee.getPassword();
        String username = employee.getUsername();


        ResultInfo loginResultInfo = employeeService.login(username, password);
        return loginResultInfo;
    }





    @Autowired
    private HttpSession httpSession;

    //退出登录
    @PostMapping("/employee/logout")
    public ResultInfo logout() {
        httpSession.invalidate();
        return ResultInfo.success("登出成功");
    }
      //查询员工 按名字
    @GetMapping("employee/find")
    public ResultInfo findByname(String name) {
        ResultInfo resultInfo = employeeService.finedBynaame(name);
        return resultInfo;
    }
    //新增员工
    @PostMapping("/employee")
    public ResultInfo save(@RequestBody Employee employee){

        employeeService.save(employee);
        return ResultInfo.success();
    };
    //查询回显
    @GetMapping("/employee/{id}")
    public ResultInfo findByid(@PathVariable Long id){
        ResultInfo resultInfo = employeeService.findByid(id);
        return resultInfo;
    }
    //修改员工
    @PutMapping("/employee")
    public ResultInfo updataByid(@RequestBody Employee employee){
         employeeService.updateByID(employee);
        return ResultInfo.success();
    }


}
